/*
 * @Author: 徐伟杰/Hyuishine
 * @Date: 2022/5/19
 * @LastEditors: 徐伟杰
 * @LastEditTime: 2022-12-09 15:48:28
 * @Description:
 * @Email: 1529315455@qq.com
 * @Company: 3xData
 * @youWant: add you want
 */

import {
  getTaskListApi,
  getLeaderListApi,
  getLeaderDepListApi,
  addTaskInfoApi,
  getDetailInfoApi,
  updateTaskInfoApi,
  report_list,
  getUnauditedListApi,
  projectName,
  wbList,
  wbPeopleList,
  updateLonLat,
  checkProject,
  addInfo,
  getAreaTree,
  getLeaderDepListApiList,
  getListStaffByAllApi,
  getHomeTaskListApi
} from "@/api/task.js";
import { changeProfileApi, changePasswordApi } from "@/api/userInfo.js";
const task = {
  state: {
    firstObj: null, // 项目登记第一步页面数据
    twoObj: null, // 项目登记第二步页面数据
    threeObj: null,
    wbList: [], // 维保列表
    taskData: [], // 任务分配时分配好的具体负责人
    WbList: {}, // 审批报告时缓存当前所需参数
  },
  mutations: {
    // 储存项目登记第一步页面数据
    storeFirst(state, data) {
      state.firstObj = data;
    },
    stroeTwo(state, data) {
      state.twoObj = data;
    },
    stroeThree(state, data) {
      state.threeObj = data;
    },
    // 修改任务分配时的分配执业人员
    setTaskData(state, data) {
      state.taskData = data;
    },

    // 审批报告时缓存当前所需参数
    setWbList(state, data) {
      console.log(data, "缓存");
      state.WbList = data;
    },
  },
  actions: {
    // 获取项目列表
    getTaskList(context, obj) {
      return new Promise((resolve, reject) => {
        getTaskListApi(obj, function (data) {
          resolve(data);
        });
      });
    },
    // 获取项目列表
    getHomeTaskList(context, obj) {
      return new Promise((resolve, reject) => {
        getHomeTaskListApi(obj, function (data) {
          resolve(data);
        });
      });
    },
    // 修改项目登记信息
    updateTaskInfoApi(context, obj) {
      return new Promise((resolve, reject) => {
        updateTaskInfoApi(obj, (data) => {
          resolve(data);
        });
      });
    },
    // 获取项目负责人-技术负责人-执业人员列表信息
    getLeaderList(context, obj) {
      return new Promise((resolve, reject) => {
        getLeaderListApi(obj, function (data) {
          resolve(data);
        });
      });
    },
    // 获取所以项目负责人-技术负责人-执业人员(包括离职人员)列表信息
    getLeaderDepList(context, obj) {
      return new Promise((resolve, reject) => {
        getLeaderDepListApi(obj, function (data) {
          resolve(data);
        });
      });
    },
    // 获取所以项目负责人-技术负责人-执业人员(包括离职人员)列表信息
    getLeaderDepLists(context, obj) {
      return new Promise((resolve, reject) => {
        getLeaderDepListApiList(obj, function (data) {
          resolve(data);
        });
      });
    },
    getListStaffByAll(context, obj) {
      return new Promise((resolve, reject) => {
        getListStaffByAllApi(obj, function (data) {
          resolve(data);
        });
      });
    },
    // 新增项目登记信息
    addTaskInfo(context, obj) {
      return new Promise((resolve, reject) => {
        addTaskInfoApi(obj, (data) => {
          resolve(data);
        });
      });
    },
    // 查看项目列表的详情页内容
    getDetailInfo(context, obj) {
      return new Promise((resolve, reject) => {
        getDetailInfoApi(obj, (data) => {
          resolve(data.data);
        });
      });
    },

    // 查看我的页面的个人信息页面查询详情接口
    getUserInfo(context, obj) {
      return new Promise((resolve, reject) => {
        changeProfileApi(obj, (data) => {
          resolve(data);
        });
      });
    },

    // 修改密码
    changePassword(context, obj) {
      return new Promise((resolve, reject) => {
        changePasswordApi(obj, (data) => {
          resolve(data);
        });
      });
    },
    // 报告列表
    report_list(context, obj) {
      return new Promise((resolve, reject) => {
        report_list(obj, (data) => {
          const code = data.code;
          if (code == "200") {
            resolve(data);
          }
        });
      });
    },
    // 获取待技术负责人审核的报告列表
    getUnauditedList(context, obj) {
      return new Promise((resolve, reject) => {
        getUnauditedListApi(obj, (data) => {
          const code = data.code;
          if (code == "200") {
            resolve(data);
          }
        });
      });
    },
    // 获取维保执行人员列表
    wbPeopleList(context, obj) {
      return new Promise((resolve, reject) => {
        wbPeopleList(obj, (data) => {
          resolve(data);
        });
      });
    },
    //  获取维保列表
    wbList(context, obj) {
      return new Promise((resolve, reject) => {
        wbList(obj, (data) => {
          resolve(data);
        });
      });
    },
    // 项目列表（任务分发下拉）
    projectName(context, obj) {
      return new Promise((resolve, reject) => {
        projectName(obj, (data) => {
          resolve(data);
        });
      });
    },
    // 修改项目的定位
    updateLonLat(context, obj) {
      return new Promise((resolve, reject) => {
        updateLonLat(obj, (data) => {
          resolve(data);
        });
      });
    },
    // 检验是否能新增项目
    checkProject(context, obj) {
      return new Promise((resolve, reject) => {
        checkProject(obj, (data) => {
          resolve(data);
        });
      });
    },
    // 添加单位人员接口
    addInfoList(context, obj) {
      return new Promise((resolve, reject) => {
        addInfo(obj, (data) => {
          resolve(data);
        });
      });
    },

    // 添加单位人员接口
    getAreaTreeApi(context, obj) {
      return new Promise((resolve, reject) => {
        getAreaTree(obj, (data) => {
          resolve(data);
        });
      });
    },
  },
};

export default task;
